/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package mapreduce;

import mapreduce.RMap;
import cfar.ff.fun.F1;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.Random;
import java.lang.Math;
import fj.data.List;
import static fj.data.List.*;

/**
 *
 * @author haoyun
 */
public class impRMap {

    public static void main(String[] args){

        F1 add10 = new F1<Integer, Integer>() {

        public Integer f(Integer a) {
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException ex) {
                    Logger.getLogger(RMap.class.getName()).log(Level.SEVERE, null, ex);
                }
                Random generator=new Random();
                double ran=generator.nextDouble();
                if(ran<0.3){
                    return null;
                }
                return a + 10;
            }
        };

        List data=list(1,2,3,4,5,6,7,8,9,10);
        List<Integer> rel=list(1,2,3,1,2,3,1,2,3,1);
        List<Double> drel=list(0.99,0.99,0.99,0.99,0.99,0.99,0.7,0.1,0.0,-0.1);
        List<Double> err= list(0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3);
        List<Integer> result=list();
        RMap rmap=new RMap();

        if(args.length>0){
            if(args[0].equals("map")){
                System.out.println("Normal map");
                result=rmap.f(add10, data);
            }
            if(args[0].equals("reliableMap")){
                System.out.println("Reliable map");
                System.out.println("Replications of jobs:");
                for (Integer o: rel){
                    System.out.print(o+", ");
                }
                System.out.println();
                result=rmap.f(add10, data, rel);
            }
            if(args[0].equals("reliableMap2")){
                System.out.println("Reliable map 2");
                result=rmap.f(add10, data, drel, err);
            }
            if(args[0].equals("normal")){
                System.out.println("Unparalleled map");
                int id=0;
                for (Object o: data){
                    result=result.snoc((Integer)add10.f(o));
                    id++;
                }
            }
        }
        else{
            System.out.println("Please enter test type");
        }

        System.out.println("Map Result: ");
        for (Integer o: result){
            System.out.print(o+", ");
        }
        System.out.println();
    }

}
